<?php
namespace Weixin\Controller;
use Think\Controller;
class SmsController extends Controller{
	//发送手机号
	public function send(){
		$verify = new \Think\Verify();
		$msg = array('returnCode'=>0,'returnInfo'=>'发送成功');
		$phone= I('phone');
		$regex = "/^1[34578]{1}\d{9}$/";
		$result = preg_match($regex,$phone);
		if($result){
			if($verify->check(I('post.verify_code'))){
				//发送短信
				$code = \Util\Character::randStr(4,'NUMBER');
				$data = array();
				$sms_data = array();
				//先发短信
				$sms_data['mobile'] = $phone;
				$sms_data['tpl_id'] = '54207';
				$sms_data['tpl_value'] = urlencode("#code#=$code");
				$result = \Util\Curl::http_post('http://push.yuuwei.com/index.php/Sms/sendSms',$sms_data);
				$result = json_encode($result,true);
				if($result['returnCode'] == 0){
					$data['mob'] = $phone;
					$data['tpl_id'] = '54207';
					$data['tpl_value'] = "#code#=$code";
					$sms_id = M('Sms')->add($data);	
				}
				
			}else{
				$msg = array('returnCode'=>2,'returnInfo'=>'图形验证码不正确');
			}	
		}else{
			$msg = array('returnCode'=>1,'returnInfo'=>'手机号码不正确');
		}
		
		echo json_encode($msg);
	}
}